package com.java1234.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.nutz.dao.Dao;
import org.nutz.dao.entity.annotation.Column;
import org.nutz.dao.util.Daos;
import org.nutz.ioc.Ioc;
import org.nutz.ioc.impl.NutIoc;
import org.nutz.ioc.impl.PropertiesProxy;
import org.nutz.ioc.loader.json.JsonLoader;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.springframework.stereotype.Service;

import com.java1234.dao.UserDao;
import com.java1234.model.PageBean;
import com.java1234.model.User;
import com.java1234.service.UserService;

@Service("userService")
public class UserServiceImpl implements UserService{

	private Ioc ioc;
	private Dao dao;
	
	private static final Log log = Logs.get();
	
	@Resource
	private UserDao userDao;
	
	@Override
	public User login(User user) {
		init();
		return userDao.login(user);
	}
	
	private void init(){
		ioc = new NutIoc(new JsonLoader("custom/dao.js"));
        dao = ioc.get(Dao.class);

        Daos.createTablesInPackage(dao, "com.java1234.model", false);
        Daos.createTablesInPackage(dao, "neo.model", false);
        
        log.warn("init - zhangwei");
	}

	@Override
	public List<User> find(PageBean pageBean, User s_user) {
		return userDao.find(pageBean, s_user);
	}

	@Override
	public int count(User s_user) {
		return userDao.count(s_user);
	}

	@Override
	public void delete(int id) {
		userDao.delete(id);
	}

	@Override
	public void add(User user) {
		userDao.add(user);
	}

	@Override
	public void update(User user) {
		userDao.update(user);
	}

	@Override
	public User loadById(int id) {
		return userDao.loadById(id);
	}

	@Override
	public boolean existUserByDeptId(int deptId) {
		return userDao.existUserByDeptId(deptId);
	}

}
